#ifndef RECEIVER_H
#define RECEIVER_H

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#include "parser.h"
#include "worker_thread.h"
#include "thread_container.h"
#include "network.h"
#include "i_socket.h"
#include "parse_exception.h"
#include "event_handler.h"
#include "notifier.h"

#include "socket/socket.h"
#include "socket/lost_connection_exception.h"

#include <iostream>

using namespace std;

namespace network {
	class receiver : public network::worker_thread,
			 public network::notifier {
	public:
		receiver(boost::shared_ptr<network::i_socket> sock, 
			 boost::shared_ptr<network::message_queue> queue,
			 boost::shared_ptr<network::parser> pars)
		: _sock(sock), _queue(queue), _pars(pars) {}
		virtual ~receiver() {}

		virtual void run();
		boost::shared_ptr<const network::i_socket> get_socket() const
		{
			return _sock;
		}

		static boost::shared_ptr<network::receiver> create(
				boost::shared_ptr<network::i_socket> sock,
				boost::shared_ptr<network::message_queue> queue,
				boost::shared_ptr<network::parser> pars)
		{
			boost::shared_ptr<network::receiver> rc(new
				network::receiver(sock, queue, pars));
			rc->_this = rc;

			return rc;
		}
	private:
		boost::shared_ptr<network::i_socket> _sock;
		boost::shared_ptr<network::message_queue> _queue;
		boost::shared_ptr<network::parser> _pars;
		
		boost::weak_ptr<network::receiver> _this;
	};
}

#endif
